package com.yanq.liancar.activity;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alipay.sdk.app.PayTask;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.view.RxToast;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.adapter.SmallBPayAdapter;
import com.yanq.liancar.adapter.SmallCFuelFillAdapter;
import com.yanq.liancar.bean.BaseDataInt;
import com.yanq.liancar.bean.PayNowBean;
import com.yanq.liancar.bean.PayResult;
import com.yanq.liancar.bean.ServiceAliPayBean;
import com.yanq.liancar.bean.SmallCFuelFillBean;
import com.yanq.liancar.bean.UserBean;
import com.yanq.liancar.bean.WeChatPayBean;
import com.yanq.liancar.url.Config;
import com.yanq.liancar.util.GlideImageLoader;
import com.yanq.liancar.util.LogUtils;
import com.yanq.liancar.util.Utils;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SmallCFuelFillingActivity extends BaseToolbarActivity {

    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_phoneNum)
    EditText etPhoneNum;
    @BindView(R.id.et_address)
    EditText etAddress;
    @BindView(R.id.gridview)
    GridView gridview;
    @BindView(R.id.tv_recharge)
    TextView tvRecharge;
    @BindView(R.id.pay_recycleview)
    RecyclerView payRecycleview;
    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.et_CarNum)
    EditText etCarNum;
    @BindView(R.id.et_FrameNum)
    EditText etFrameNum;
    @BindView(R.id.et_CardNum)
    EditText etCardNum;
    @BindView(R.id.tv_Notes)
    TextView tvNotes;
    @BindView(R.id.tv_EngineOil)
    TextView tvEngineOil;
    @BindView(R.id.view_EngineOil)
    View viewEngineOil;
    @BindView(R.id.ll_EngineOil)
    LinearLayout llEngineOil;
    @BindView(R.id.tv_parts)
    TextView tvParts;
    @BindView(R.id.view_parts)
    View viewParts;
    @BindView(R.id.ll_parts)
    LinearLayout llParts;
    @BindView(R.id.ll_gouka)
    LinearLayout llGouka;
    @BindView(R.id.ll_chongzhi)
    LinearLayout llChongzhi;
    private List<SmallCFuelFillBean> list = new ArrayList<>();
    private SmallCFuelFillAdapter smallCFuelFillAdapter;
    private SmallBPayAdapter adapter;
    private List<PayNowBean> payNowBeanList = new ArrayList<>();
    private int payPrice, price, isMember;
    private String orderID;
    private static final int SDK_PAY_FLAG = 1;
    private IWXAPI api;
    private static final String APP_ID = "wxd2e19fc6b6f17ec0";
    private int type = 1;
    private int status;
    private List<Integer> imageUrl;
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    @SuppressWarnings("unchecked")
                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                    /**

                     对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。

                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    LogUtils.e("resultInfo====", resultInfo);
                    LogUtils.e("resultStatus====", resultStatus);
                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, "9000")) {
                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                        //Toast.makeText(SmallCFuelFillingActivity.this, "支付成功", Toast.LENGTH_SHORT).show();
                        RxToast.success("支付成功");
                        //                        Bundle bundle=new Bundle();
                        //                        bundle.putString("orderID",orderID);
                        //                        RxActivityTool.skipActivityAndFinish(SmallCFuelFillingActivity.this, PurchaseSuccessActivity.class,bundle);
                    } else {

                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。
                        //Toast.makeText(SmallCFuelFillingActivity.this, "支付失败", Toast.LENGTH_SHORT).show();
                        RxToast.success("支付失败");
                    }
                    break;
                }

            }

        }

    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_small_fuelfillingactivity);
        ButterKnife.bind(this);
        Utils.setStatusBar(this, true, false);
        mTvTitle.setText("特惠加油");

        initView();
        initBannerData();
        queryMember();

        tvRecharge.setText("购卡");

        tvEngineOil.setTextColor(getResources().getColor(R.color.main_color));
        viewEngineOil.setVisibility(View.VISIBLE);
        llGouka.setVisibility(View.VISIBLE);

        tvParts.setTextColor(getResources().getColor(R.color.background_content));
        viewParts.setVisibility(View.GONE);
        llChongzhi.setVisibility(View.GONE);

        smallCFuelFillAdapter = new SmallCFuelFillAdapter(this, list);
        gridview.setAdapter(smallCFuelFillAdapter);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //                if (position > 1 && isMember == 0) {
                //                    bottomDialog1();
                //                } else {
                //                    for (int i = 0; i < list.size(); i++) {
                //                        if (i == position) {
                //                            list.get(i).setChecked(true);
                //                            payPrice = list.get(position).getDiscount_price();
                //                            price = list.get(position).getPrice();
                //                        } else {
                //                            list.get(i).setChecked(false);
                //                        }
                //                    }
                //                    smallCFuelFillAdapter.setData(list);
                //                }
                if (isMember != 0) {
                    if (position > 1) {
                        if (isMember == 2) {
                            for (int i = 0; i < list.size(); i++) {
                                if (i == position) {
                                    list.get(i).setChecked(true);
                                    payPrice = list.get(position).getDiscount_price();
                                    price = list.get(position).getPrice();
                                } else {
                                    list.get(i).setChecked(false);
                                }
                            }
                            smallCFuelFillAdapter.setData(list);
                        } else {
                            bottomDialog2(1);
                        }
                    } else {
                        if (isMember == 1) {
                            for (int i = 0; i < list.size(); i++) {
                                if (i == position) {
                                    list.get(i).setChecked(true);
                                    payPrice = list.get(position).getDiscount_price();
                                    price = list.get(position).getPrice();
                                } else {
                                    list.get(i).setChecked(false);
                                }
                            }
                            smallCFuelFillAdapter.setData(list);
                        } else {
                            bottomDialog2(2);
                        }

                    }
                } else {
                    bottomDialog1();
                }

            }
        });

        initData();
        initRecyclerView();
    }

    private void initView() {
        SmallCFuelFillBean bean = new SmallCFuelFillBean();
        bean.setPrice(500);
        bean.setChecked(true);
        bean.setDiscount_price(485);
        bean.setId(1);
        list.add(bean);
        SmallCFuelFillBean bean1 = new SmallCFuelFillBean();
        bean1.setPrice(1000);
        bean1.setDiscount_price(970);
        bean1.setId(2);
        list.add(bean1);
        SmallCFuelFillBean bean2 = new SmallCFuelFillBean();
        bean2.setPrice(500);
        bean2.setDiscount_price(470);
        bean2.setId(3);
        list.add(bean2);
        SmallCFuelFillBean bean4 = new SmallCFuelFillBean();
        bean4.setPrice(1000);
        bean4.setDiscount_price(940);
        bean4.setId(4);
        list.add(bean4);
    }

    private void initBannerData() {
        imageUrl = new ArrayList<>();
        imageUrl.add(R.mipmap.banner1);
        imageUrl.add(R.mipmap.banner2);
        imageUrl.add(R.mipmap.banner3);
        imageUrl.add(R.mipmap.banner4);
        imageUrl.add(R.mipmap.banner5);
        imageUrl.add(R.mipmap.banner6);
        banner.setImageLoader(new GlideImageLoader())
                .setImages(imageUrl)//设置图片集合
                .setDelayTime(3000)//设置轮播时间
                .setBannerStyle(BannerConfig.CIRCLE_INDICATOR)//设置指示器位置（当banner模式中有指示器时）
                .setIndicatorGravity(BannerConfig.CENTER)
                .start();//banner设置方法全部调用完毕时最后调用
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                //ToastUtils.showToast(SmallBGoodsDetailsActivity.this, "您点击了第" + (mBanners.get(position).type + 1) + "张照片");
            }
        });
    }

    private void initData() {
        PayNowBean bean2 = new PayNowBean();
        bean2.setNum(1);
        bean2.setName("支付宝支付");
        bean2.setChecked(true);
        payNowBeanList.add(bean2);
        PayNowBean bean = new PayNowBean();
        bean.setNum(2);
        bean.setName("微信支付");
        bean.setChecked(false);
        payNowBeanList.add(bean);
    }

    private void initRecyclerView() {
        payRecycleview.setHasFixedSize(true);
        payRecycleview.setNestedScrollingEnabled(false);
        payRecycleview.setLayoutManager(new LinearLayoutManager(this));
        adapter = new SmallBPayAdapter(R.layout.item_small_b_pay, payNowBeanList);
        payRecycleview.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i = 0; i < payNowBeanList.size(); i++) {
                    if (position == i) {
                        payNowBeanList.get(i).setChecked(true);
                        payNowBeanList.get(i).getName();
                        type = payNowBeanList.get(position).getNum();
                    } else {
                        payNowBeanList.get(i).setChecked(false);
                    }
                }
                adapter.setNewData(payNowBeanList);
            }
        });
    }


    @OnClick({R.id.tv_recharge, R.id.tv_Notes, R.id.ll_EngineOil, R.id.ll_parts})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_recharge:
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                // 隐藏软键盘
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
                if (!"".equals(UserBean.getcToken(this)) && !TextUtils.isEmpty(UserBean.getcToken(this))) {
                    if (status==0){             //购卡
                        if (buyIsNull()){
                            if (type == 1) {
                                addStores();
                            } else {
                                weChatPayment();
                            }
                        }
                    }else {                     //充值
                        if (!TextUtils.isEmpty(etCardNum.getText().toString().trim())){
                            if (type == 1) {
                                aliRecharge();
                            } else {
                                weChatRecharge();
                            }
                        }else {
                            RxToast.info("请输入加油卡号码");
                        }
                    }
                } else {
                    bottomDialog();
                }
                break;
            case R.id.tv_Notes:
                RxActivityTool.skipActivity(mContext, PurchaseNoticeActiviity.class);
                break;
            case R.id.ll_EngineOil:
                tvEngineOil.setTextColor(getResources().getColor(R.color.main_color));
                viewEngineOil.setVisibility(View.VISIBLE);
                llGouka.setVisibility(View.VISIBLE);

                tvParts.setTextColor(getResources().getColor(R.color.background_content));
                viewParts.setVisibility(View.GONE);
                llChongzhi.setVisibility(View.GONE);

                tvRecharge.setText("购卡");
                status=0;
                break;
            case R.id.ll_parts:
                tvEngineOil.setTextColor(getResources().getColor(R.color.background_content));
                viewEngineOil.setVisibility(View.GONE);
                llGouka.setVisibility(View.GONE);

                tvParts.setTextColor(getResources().getColor(R.color.main_color));
                viewParts.setVisibility(View.VISIBLE);
                llChongzhi.setVisibility(View.VISIBLE);

                tvRecharge.setText("充值");
                status=1;
                break;
        }
    }

    private void queryMember() {
        OkGo.<String>post(Config.s + "llc/api/selectVipByUser")
                .tag(this)
                .params("token", UserBean.getcToken(mContext))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseDataInt baseBean = gson.fromJson(response.body(), BaseDataInt.class);
                        if (baseBean.isIsSuccess()) {
                            isMember = baseBean.getData();
                            if (isMember == 2) {
                                for (int i = 0; i < list.size(); i++) {
                                    if (i == 2) {
                                        list.get(2).setChecked(true);
                                        payPrice = list.get(2).getDiscount_price();
                                        price = list.get(2).getPrice();
                                    } else {
                                        list.get(i).setChecked(false);
                                    }
                                }
                                smallCFuelFillAdapter.setData(list);
                            } else {
                                payPrice = 485;
                                price = 500;
                            }
                        } else {
                            // RxToast.error(baseBean.getOutputMessage());
                        }
                    }
                });

    }

    //支付宝购卡
    private void addStores() {
            OkGo.<String>post(Config.s + "llc/payOilcartController/payOilCart")
                    .tag(this)
                    .params("token", UserBean.getcToken(mContext))
                    .params("tel", etPhoneNum.getText().toString().trim())
                    .params("gainName", etName.getText().toString().trim())
                    .params("address", etAddress.getText().toString().trim())
                    .params("payType", type)
                    .params("payPrice", payPrice)
                    .params("price", price)
                    .params("isVipPay", isMember)
                    .params("driNum", etCarNum.getText().toString().trim())
                    .params("carNum", etFrameNum.getText().toString().trim())
                    .params("oilCartNum", etCardNum.getText().toString().trim())
                    .execute(new StringCallback() {
                        @Override
                        public void onSuccess(Response<String> response) {
                            Gson gson = new Gson();
                            final ServiceAliPayBean baseBean = gson.fromJson(response.body(), ServiceAliPayBean.class);
                            if (baseBean.isIsSuccess()) {
                                final String info = baseBean.getData().getSigned_content();
                                LogUtils.e("加签info===", info);
                                if ("".equals(info) || !TextUtils.isEmpty(info)) {
                                    Runnable payRunnable = new Runnable() {
                                        @Override
                                        public void run() {
                                            PayTask alipay = new PayTask(SmallCFuelFillingActivity.this);
                                            Map<String, String> result = alipay.payV2(info, true);

                                            Message msg = new Message();
                                            msg.what = SDK_PAY_FLAG;
                                            msg.obj = result;
                                            mHandler.sendMessage(msg);
                                            orderID = baseBean.getData().getOnum();
                                            LogUtils.e("13123131", baseBean.getData().getOnum() + "");
                                        }
                                    };
                                    // 必须异步调用
                                    Thread payThread = new Thread(payRunnable);
                                    payThread.start();
                                }
                            } else {
                                RxToast.info(baseBean.getOutputMessage());
                                //finish();
                            }
                        }
                    });
    }

    //支付宝充值
    private void aliRecharge(){
        OkGo.<String>post(Config.s + "llc/payOilcartController/rechargeOilCart")
                .tag(this)
                .params("token", UserBean.getcToken(mContext))
                .params("oilCartNum", etCardNum.getText().toString().trim())
                .params("isVipPay", isMember)
                .params("payPrice", payPrice)
                .params("price", price)
                .params("payType", type)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        final ServiceAliPayBean baseBean = gson.fromJson(response.body(), ServiceAliPayBean.class);
                        if (baseBean.isIsSuccess()) {
                            final String info = baseBean.getData().getSigned_content();
                            LogUtils.e("加签info===", info);
                            if ("".equals(info) || !TextUtils.isEmpty(info)) {
                                Runnable payRunnable = new Runnable() {
                                    @Override
                                    public void run() {
                                        PayTask alipay = new PayTask(SmallCFuelFillingActivity.this);
                                        Map<String, String> result = alipay.payV2(info, true);

                                        Message msg = new Message();
                                        msg.what = SDK_PAY_FLAG;
                                        msg.obj = result;
                                        mHandler.sendMessage(msg);
                                        orderID = baseBean.getData().getOnum();
                                        LogUtils.e("13123131", baseBean.getData().getOnum() + "");
                                    }
                                };
                                // 必须异步调用
                                Thread payThread = new Thread(payRunnable);
                                payThread.start();
                            }
                        } else {
                            RxToast.info(baseBean.getOutputMessage());
                            //finish();
                        }
                    }
                });
    }


    //微信购卡
    private void weChatPayment() {
            api = WXAPIFactory.createWXAPI(this, APP_ID);
            api.registerApp(APP_ID);
            OkGo.<String>post(Config.s + "llc/payOilcartController/payOilCartWX")
                    .tag(this)
                    .params("token", UserBean.getcToken(mContext))
                    .params("tel", etPhoneNum.getText().toString().trim())
                    .params("gainName", etName.getText().toString().trim())
                    .params("address", etAddress.getText().toString().trim())
                    .params("payType", type)
                    .params("payPrice", payPrice)
                    .params("price", price)
                    .params("isVipPay", isMember)
                    .params("driNum", etCarNum.getText().toString().trim())
                    .params("carNum", etFrameNum.getText().toString().trim())
                    .params("oilCartNum", etCardNum.getText().toString().trim())
                    .execute(new StringCallback() {
                        @Override
                        public void onSuccess(Response<String> response) {
                            Gson gson = new Gson();
                            WeChatPayBean baseBean = gson.fromJson(response.body(), WeChatPayBean.class);
                            if (baseBean.isIsSuccess()) {
                                if (baseBean.getData() != null) {
                                    PayReq request = new PayReq();
                                    request.appId = baseBean.getData().getAppid();
                                    request.partnerId = baseBean.getData().getPartnerId();
                                    request.prepayId = baseBean.getData().getPrepayId();
                                    request.packageValue = baseBean.getData().getPackageValue();
                                    request.nonceStr = baseBean.getData().getNonceStr();
                                    request.timeStamp = baseBean.getData().getTimeStamp();
                                    request.sign = baseBean.getData().getSign();
                                    api.sendReq(request);
                                    //finish();
                                    LogUtils.e(" api.sendReq=====", api.sendReq(request) + "");
                                }
                            } else {
                                RxToast.info(baseBean.getOutputMessage());
                                //finish();
                            }
                        }


                    });
        }

        //微信充值
    private void weChatRecharge(){
        api = WXAPIFactory.createWXAPI(this, APP_ID);
        api.registerApp(APP_ID);
        OkGo.<String>post(Config.s + "llc/payOilcartController/rechargeOilCartWX")
                .tag(this)
                .params("token", UserBean.getcToken(mContext))
                .params("payType", type)
                .params("payPrice", payPrice)
                .params("price", price)
                .params("isVipPay", isMember)
                .params("oilCartNum", etCardNum.getText().toString().trim())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        WeChatPayBean baseBean = gson.fromJson(response.body(), WeChatPayBean.class);
                        if (baseBean.isIsSuccess()) {
                            if (baseBean.getData() != null) {
                                PayReq request = new PayReq();
                                request.appId = baseBean.getData().getAppid();
                                request.partnerId = baseBean.getData().getPartnerId();
                                request.prepayId = baseBean.getData().getPrepayId();
                                request.packageValue = baseBean.getData().getPackageValue();
                                request.nonceStr = baseBean.getData().getNonceStr();
                                request.timeStamp = baseBean.getData().getTimeStamp();
                                request.sign = baseBean.getData().getSign();
                                api.sendReq(request);
                                //finish();
                                LogUtils.e(" api.sendReq=====", api.sendReq(request) + "");
                            }
                        } else {
                            RxToast.info(baseBean.getOutputMessage());
                            //finish();
                        }
                    }


                });
    }

        //
        //                String order_id=Utils.md5(UUID.randomUUID().toString().replace("_","")+System.currentTimeMillis());
        //                Log.e("dadadassda", price.replace("¥",""));
        //                WechatPayTools.wechatPayUnifyOrder(mContext,
        //                    "wxd2e19fc6b6f17ec0", //微信分配的APP_ID
        //                    "1513987451", //微信分配的 PARTNER_ID (商户ID)
        //                    "042732fcd9da459da435cdffba5bd01d", //微信分配的 PRIVATE_KEY (私钥)
        //                    new WechatModel(order_id, //订单ID (唯一)
        //                                    price.replace("¥",""), //价格
        //                                tvPayName.getText().toString().trim(), //商品名称
        //                                "qqqqqqq"), //商品描述详情
        //                                        new OnSuccessAndErrorListener() {
        //                @Override
        //                public void onSuccess(String s) {
        //                    RxToast.success(s);
        //                }
        //
        //                @Override
        //                public void onError(String s) {
        //                    RxToast.error(s);
        //                }
        //            });



    private boolean buyIsNull() {
        if (TextUtils.isEmpty(etName.getText().toString().trim())) {
            RxToast.info("请填写联系人");
            return false;
        }
        if (TextUtils.isEmpty(etPhoneNum.getText().toString().trim())) {
            RxToast.info("请填写手机号码");
            return false;
        }
        if (TextUtils.isEmpty(etAddress.getText().toString().trim())) {
            RxToast.info("请填写地址");
            return false;
        }
        if (TextUtils.isEmpty(etCarNum.getText().toString().trim())) {
            RxToast.info("请填写车牌号码");
            return false;
        }

        return true;
    }

    //登陆验证
    private void bottomDialog() {
        final Dialog bottomDialog = new Dialog(this, R.style.BottomDialog);
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_landing_verification, null);
        bottomDialog.setContentView(contentView);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels;
        //        params.bottomMargin = MyUtils.dp2px(this, 8f);
        contentView.setLayoutParams(params);
        bottomDialog.getWindow().setGravity(Gravity.CENTER);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation2);
        bottomDialog.show();

        //确定
        TextView tv_confirm = bottomDialog.findViewById(R.id.submit);
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RxActivityTool.skipActivity(SmallCFuelFillingActivity.this, LoginActivity.class);
                bottomDialog.dismiss();
            }
        });
        //取消
        TextView tv_cancle = bottomDialog.findViewById(R.id.cancel);
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomDialog.dismiss();
            }
        });
    }

    //
    private void bottomDialog2(int num) {
        final Dialog bottomDialog = new Dialog(this, R.style.BottomDialog);
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_landing_verification, null);
        bottomDialog.setContentView(contentView);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels;
        //        params.bottomMargin = MyUtils.dp2px(this, 8f);
        contentView.setLayoutParams(params);
        bottomDialog.getWindow().setGravity(Gravity.CENTER);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation2);
        bottomDialog.show();
        //标题
        TextView textView = bottomDialog.findViewById(R.id.title);
        //确定
        TextView tv_confirm = bottomDialog.findViewById(R.id.submit);
        //取消
        TextView tv_cancle = bottomDialog.findViewById(R.id.cancel);

        if (num == 1) {
            textView.setText("铂金会员才可以享受此优惠");
        } else {
            textView.setText("您是铂金会员，建议使用做高优惠");
        }

        tv_confirm.setText("确定");
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomDialog.dismiss();
            }
        });

        tv_cancle.setText("取消");
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomDialog.dismiss();
            }
        });
    }

    private void bottomDialog1() {
        final Dialog bottomDialog = new Dialog(this, R.style.BottomDialog);
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_landing_verification, null);
        bottomDialog.setContentView(contentView);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels;
        //        params.bottomMargin = MyUtils.dp2px(this, 8f);
        contentView.setLayoutParams(params);
        bottomDialog.getWindow().setGravity(Gravity.CENTER);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation2);
        bottomDialog.show();
        TextView textView = bottomDialog.findViewById(R.id.title);
        textView.setText("VIP会员才可以享受94折优惠");
        //确定
        TextView tv_confirm = bottomDialog.findViewById(R.id.submit);
        tv_confirm.setText("购买VIP");
        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RxActivityTool.skipActivity(SmallCFuelFillingActivity.this, SmallCBuyVIPActivity.class);
                bottomDialog.dismiss();
            }
        });
        //取消
        TextView tv_cancle = bottomDialog.findViewById(R.id.cancel);
        tv_cancle.setText("取消");
        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bottomDialog.dismiss();
            }
        });
    }

}
